package org.xtext.runtime.lang;


import java.util.Arrays;
import java.util.List;

import org.xtext.runtime.library.Library;

public class Strings extends Library {
	/**
	 * 
	 * @param s
	 * @return
	 */
	@TERM
	public int length(String s) {
		return s.length();
	}
	/**
	 * 
	 * @param string
	 * @param start
	 * @param end
	 * @return
	 */
	@TERM
	public String substring(String string, int start, int end){
		return string.substring(start, end);
	}
	
	@TERM
	public List<String> split(String string, String delimiter) {
		return Arrays.asList(string.split(delimiter));
	}
	
	/**
	 * 
	 * @param string
	 * @param regex
	 * @return
	 */
	@TERM
	public boolean matches(String string, String regex){
		return string.matches(regex);
	}
	
	/**
	 * 
	 * @param string
	 * @param replaceMe
	 * @param withMe
	 * @return
	 */
	@TERM
	public String replace(String string, char replaceMe, char withMe){
		return string.replace(replaceMe, withMe);
	}
	/**
	 * 
	 * @param string
	 * @param replaceMe
	 * @param withMe
	 * @return
	 */
	@TERM
	public String replace(String string, String replaceMe, String withMe){
		return string.replaceAll(replaceMe, withMe);
	}
		
	/**
	 * @param s1
	 * @param s2
	 * @return
	 */
	@FORMULA 
	public boolean equal(String s1, String s2){
		return s1.equals(s2);
	}
	
	/**
	 * This method indicates whether the string s1 starts with 
	 * the characters in s2.
	 * @param s1 The String we are checking
	 * @param s2 the proposed Start of the string
	 * @return true if the string s1 starts with the string s2
	 */
	@FORMULA
	public boolean startsWith(String s1, String s2){
		return s1.startsWith(s2);
	}
	
	@TERM
	public String toString(int value) {
		return "" + value;
	}
}
